package entities;

import java.awt.Image;

import javax.swing.ImageIcon;

import logic.Utilities;
import constants.WallType;

/** Wall's class for the brick breaker game.
 * @author Team 1
 *
 */
@SuppressWarnings("serial")
public class Wall extends Entity {

	private ImageIcon icon;		//The ImageIcon of the label.
	private WallType type;		//The wall type.
	
	/** The wall's constructor.
	 * @param x : the entity's upper-left corner's x coordinate.
	 * @param y : the entity's upper-left corner's y coordinate.
	 * @param type : the wall type.
	 * @param xScale : the x resize scale. If it's lower than one it reduces the images original width, increase it otherwise.
	 * @param yScale : the y resize scale. If it's lower than one it reduces the images original height, increase it otherwise.
	 */
	public Wall(int x, int y, WallType type, float xScale, float yScale) {
		super(x, y);
		this.type = type;
		Image image = Utilities.loadImage("res/" + type + ".png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/" + type + ".png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x,(int) this.y, this.width, this.height);
	}
	
	/** Returns the wall type.
	 * @return type.
	 */
	public WallType getType() {
		return type;
	}
	
	public void resize(float xScale, float yScale) {
		super.resize(xScale, yScale);
		this.icon = new ImageIcon(Utilities.resizeImage(xScale, yScale, "res/" + type.toString() +".png"));
		this.setIcon(icon);
	}
	
	/** Return the walls's width for all resolution giving the windows width divided by 1280.
	 * @param type : the type of wall.
	 * @param xScale : The windows horizontal proportion value.
	 * @return The value of the ball's width depending on the horizontal scale.
	 */
	public static int getWidth(WallType type, float xScale) {
		if(type.equals(WallType.LEFTWALL) || type.equals(WallType.RIGHTWALL)
				|| type.equals(WallType.UPPERLEFTWALL) || type.equals(WallType.UPPERRIGHTWALL)) {
			return Math.round(17 * xScale);
		} else {
			return Math.round(1246 * xScale);
			
		}
	}
	
	/**Return the wall's height for all resolution giving the windows height divided by 720.
	 * @param type : the type of wall.
	 * @param yScale : The windows vertical proportion value.
	 * @return The value of the ball's height depending on the vertical scale.
	 */
	public static int getHeight(WallType type, float yScale) {
		if(type.equals(WallType.UPPERLEFTWALL) || type.equals(WallType.UPPERRIGHTWALL)
				|| type.equals(WallType.UPWALL)) {
			return Math.round(17 * yScale);
		} else {
			return Math.round(673 * yScale);
			
		}
	}
}
